package rabbitMqLearn.spring_boot.publish;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import rabbitMqLearn.mq.config.Config;
import rabbitMqLearn.spring_boot.confg.SpringConfig;

import java.util.Arrays;
import java.util.Scanner;

@Component
public class PublishConsumer {

    @RabbitListener(queues = {SpringConfig.PUBLISH_FANOUT_QUEUE1, SpringConfig.PUBLISH_FANOUT_QUEUE2})
    public void fanout1(Message msg) {
        System.out.printf("收到消息 %s: %s%n", msg.getMessageProperties().getConsumerQueue(), new String(msg.getBody()));
    }

    @RabbitListener(queues = {SpringConfig.PUBLISH_ROUTING_QUEUE1, SpringConfig.PUBLISH_ROUTING_QUEUE2})
    public void routing(Message msg) {
        System.out.printf("收到消息 %s: %s%n", msg.getMessageProperties().getConsumerQueue(), new String(msg.getBody()));
    }

    @RabbitListener(queues = {SpringConfig.TOPIC_QUEUE1, SpringConfig.TOPIC_QUEUE2})
    public void topic(Message msg) {
        System.out.printf("收到消息 %s: %s%n", msg.getMessageProperties().getConsumerQueue() + " " + msg.getMessageProperties().getReceivedRoutingKey()
                , new String(msg.getBody()));
    }


}
